home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / TURB_VIS / OGRID100 / TCHASH.INT < prev    next >
Text File  |  1994-12-28  |  2KB  |  62 lines

  1.  
  2. { Copyright (c) 1989,90 by Borland International, Inc. }
  3.  
  4. unit TCHash;
  5. { Turbo Pascal 6.0 object-oriented example hash tables.
  6.   This unit is used by TCALC.PAS.
  7.   See TCALC.DOC for an more information about this example.
  8. }
  9.  
  10. {$S-}
  11.  
  12. interface
  13.  
  14. uses TCUtil;
  15.  
  16. { This unit allows you to implement hash tables.  Each hash table is composed
  17.   of a number of "buckets", each of which points to a linked list of data
  18.   entries.  The bucket that a particular data entry goes into is determined
  19.   by the HashValue function. }
  20.  
  21. const
  22.   MaxBuckets = 1000;
  23.   MaxHashItemSize = 256;
  24.  
  25. type
  26.   BucketRange = 1..MaxBuckets;
  27.   HashItemSizeRange = 1..MaxHashItemSize;
  28.   HashItemData = array[0..Pred(MaxHashItemSize)] of Byte;
  29.   HashItemDataPtr = ^HashItemData;
  30.   HashItemPtr = ^HashItem;
  31.   HashItem = record
  32.     Next : HashItemPtr;
  33.     Data : HashItemData;
  34.   end;
  35.   HashItemArray = array[BucketRange] of HashItemPtr;
  36.   HashTable = object
  37.     Buckets : BucketRange;
  38.     Items : Longint;
  39.     CurrItem : HashItemPtr;
  40.     CurrBucket : BucketRange;
  41.     HashData : ^HashItemArray;
  42.     constructor Init(InitBuckets : BucketRange);
  43.     destructor Done;
  44.     function Add : Boolean;
  45.     procedure Delete(Deleted : Pointer);
  46.     function FirstItem : HashItemPtr;
  47.     function NextItem : HashItemPtr;
  48.     function Change : Boolean;
  49.     function Search : HashItemPtr;
  50.     function HashValue : LongInt; virtual;
  51.     function Found(Item : HashItemPtr) : Boolean; virtual;
  52.     procedure CreateItem(var Item : HashItemPtr); virtual;
  53.     function ItemSize : HashItemSizeRange; virtual;
  54.     function CurrItemSize(Item : HashItemPtr) : HashItemSizeRange; virtual;
  55.   end;
  56.  
  57. implementation
  58.  
  59. ...
  60.  
  61. end.
  62.